package com.cheyun.netsalev3.view.dm.detail

import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.adapter.HomePageAdapter
import com.cheyun.netsalev3.databinding.ActivityDmDetailsBinding
import com.cheyun.netsalev3.utils.BaseActivity
import com.cheyun.netsalev3.utils.InjectorUtils
import com.cheyun.netsalev3.viewmodel.DmClueDetailsActivityViewModel
import com.jeremyliao.liveeventbus.LiveEventBus

/**
 * 线索详情
 */
class DmDetailsActivity : BaseActivity<ActivityDmDetailsBinding>() {
    var id = ""

    override fun initContentView(): Int {
        return R.layout.activity_dm_details
    }


    override fun initViewModel(): ViewModel? {
        id = intent.getStringExtra("id");

        titleList = arrayListOf("线索详情", "历史记录")

        val factory = InjectorUtils.getDmClueDetailsViewModelFactory(id)
        return ViewModelProviders.of(this, factory).get(DmClueDetailsActivityViewModel::class.java)
    }

    lateinit var titleList: ArrayList<String>
    override fun initView() {
        var list = ArrayList<Fragment>()
        list.add(DmDetailsFragment())
        list.add(DmHistoryRecordFragment())
        var adapter = HomePageAdapter(supportFragmentManager, list)
        adapter.titles = titleList
        binding.viewPager.adapter = adapter
        binding.tabLayout.setSelectedTabIndicator(R.drawable.tab_indicator)
        binding.tabLayout.setupWithViewPager(binding.viewPager)

        binding.leftBut.setOnClickListener {
            finish()
        }
        LiveEventBus.get()
                .with("dmclueupdatge", String::class.java)
                .observe(this, Observer {
                    binding.viewModel?.refreshDetail()
                })
    }

    override fun initData() {

    }


}
